/***************************************************************************
 创建者: 华磊
 开始时间: 2019.11.15
 copyright: (C) 华友高科
 修改说明:
 ***************************************************************************
 *  @file .h
 *  功能:
 * 龙门控制
 *
 *                                                                         *
 ***************************************************************************/

#ifndef GANTRYCONTROL_H
#define GANTRYCONTROL_H
#include <QString>
#include <QVector>
#include <QMutex>

//enum E_COUPLE_TYPE
//{
//    E_COUPLE_TYPE_COMMON,
//    E_COUPLE_TYPE_MAP_R,
//};

struct GantryCtrConfigParameter
{
    volatile bool isValid;//是否工作
//    E_COUPLE_TYPE coupleType;
    int driveAxisId;
    int followAxisId;
    volatile double followOffsetValue;
    double allowMaxFollowOffset;
    double kp_errorControl;
    double maxConpensation;
//    double coupleRatio;
};

class AxisGroup;
class MotionMessage;
class FilteringAlgorithm;

class GantryControl
{
public:
    GantryControl(QString configFileIn, MotionMessage *motionMessageIn, int robotIdIn, AxisGroup *axisGroupIn);
public:
    bool isGantryControlFollowAxisWork(int followAxisId);
    bool isInitialOk();
    bool isUseThisModule();
    int loopRealtimeOnce();
    int setGantryControlEnable(int coupleId,bool isEnableIn);//注意线程安全问题，没有锁
    int setGantryControlOffset(int coupleId,double offfsetValueIn);//注意线程安全问题，没有锁
    int resetAll();

private:

    int calculateOneCouple(const GantryCtrConfigParameter &couplePara,AxisGroup *axisGroupIn);
    int initialConfigFile(QString configFileName);
    void addMsg(int messageLevel, std::string componentName, std::string messageType, int messageCode
                , int robotIdIn, int parameter1=0, int parameter2=0, double parameter3=0,
                double parameter4=0, std::string messageInfo="");


private:
    bool isInitialOkStatus;
    bool isUseGantryControl;
    MotionMessage *motionMessage;
    int robotId;
    AxisGroup *axisGroup;
    QVector<GantryCtrConfigParameter> coupleParameterList;
//    FilteringAlgorithm* filtering_mapFollowAxisPos;
//    QMutex usingMutex;//有trajMutex锁保护了,可以不用该锁.外层有一个锁，２个锁可能陷入deadlock
};

#endif // GANTRYCONTROL_H
